﻿using System.ServiceModel;
using System.Web;
using NHibernate;

namespace Sripirom.ATS.Repository.NH.SessionStorage
{
    public class OperationContextContainer : ISessionStorageContainer
    {
        private string _sessionKey = "NHSession";
                               
        public ISession GetCurrentSession()
        {
            ISession nhSession = null;


            if (OperationContext.Current.IncomingMessageProperties.ContainsKey(_sessionKey))
                nhSession = (ISession)OperationContext.Current.IncomingMessageProperties[_sessionKey];

            return nhSession;
        }

        public void Store(ISession session)
        {
            if (OperationContext.Current.IncomingMessageProperties.ContainsKey(_sessionKey))
                OperationContext.Current.IncomingMessageProperties[_sessionKey] = session;
            else
                OperationContext.Current.IncomingMessageProperties.Add(_sessionKey, session);
        }
    }

}
